<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
use app\index\model\Area;
use app\index\model\User;
use app\index\model\DeliveryAddress;

// 应用公共文件
function status($status) {
    if($status == 1) {
        $str = "<span class='label label-success radius'>正常</span>";
    }elseif($status ==0) {
        $str = "<span class='label label-default radius'>待审</span>";
    }else {
        $str = "<span class='label label-danger radius'>删除</span>";
    }
    return $str;
}

// 轮播图开关
function banner($status){
	if($status == 1) {
        $str = "<span class='label label-success radius'>启用</span>";
    }elseif($status ==0) {
        $str = "<span class='label label-default radius'>停用</span>";
    }else {
        $str = "<span class='label label-danger radius'>删除</span>";
    }
    return $str;
}

function show($status,$message='',$data=[]){
    return [
        'status' => $status,
        'message' => $message,
        'data' => $data,
    ];
}

// 根据用户ID获取用户名
function getUserById($id)
{
    $userModel = new User();
    $uname = $userModel->where('id',$id)->column('username');
    return $uname[0];
}

// 根据地址ID获取收货地址
function getAddrById($aid)
{
    $addr = new DeliveryAddress();
    $addrs = $addr->get($aid);
    $province = getProvince($addrs->province);
    $city = getProvince($addrs->city);
    $details = $addrs->detail_address;
    return $province . ' ' . $city . ' ' .$details;
}

// 根据地址ID获取联系方式
function getMobileById($aid)
{
    $addr = new DeliveryAddress();
    $addrs = $addr->get($aid);
    return $addrs->mobile;
}
// 根据地址ID获取收件人
function getConsingerById($aid)
{
    $addr = new DeliveryAddress();
    $addrs = $addr->get($aid);
    return $addrs->consigner;
}

// 获取省份
function getProvince($id)
{  
    $area = new Area();
    return $area->getAddressById($id);
}

function orderStatus($value){
    $status = [0=>'未完成订单',1=>'未付款',2=>'已付款，未发货',3=>'已发货',4=>'已收货',5=>'已评价'];
    return $status[$value];
}

function order_status($status) {
    if($status == 1) {
        $str = "<span class='label label-default radius'>买家未付款</span>";
    }elseif($status ==2) {
        $str = "<span class='label label-danger radius'>已付款，未发货</span>";
    }elseif($status == 3) {
        $str = "<span class='label label-success radius'>已发货</span>";
    } elseif($status == 4){
        $str = "<span class='label label-success radius'>买家已收货</span>";
    }elseif($status == 5){
        $str = "<span class='label label-success radius'>买家已评价</span>";
    }
    return $str;
}

function plstatus($status) {
    if($status == 0) {
        $str = "<span class='label label-success radius'>显示</span>";
    }elseif($status ==1) {
        $str = "<span class='label label-default radius'>屏蔽</span>";
    }else {
        $str = "<span class='label label-danger radius'>删除</span>";
    }
    return $str;
}